<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>update (Bullet)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File bullet.rb, line 18</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update</span>
    <span class="ruby-ivar">@y</span> <span class="ruby-operator">-=</span> <span class="ruby-constant">Speed</span> <span class="ruby-comment cmt"># move up</span>
        
    <span class="ruby-identifier">collide</span> = <span class="ruby-keyword kw">false</span>    
    <span class="ruby-comment cmt"># collisions against aliens</span>
    <span class="ruby-constant">Engine</span><span class="ruby-operator">::</span><span class="ruby-constant">Game</span>.<span class="ruby-identifier">sprites</span>[<span class="ruby-constant">Alien</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">alien</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">collision?</span>(<span class="ruby-identifier">alien</span>)
        <span class="ruby-identifier">collide</span> = <span class="ruby-keyword kw">true</span>
        <span class="ruby-identifier">alien</span>.<span class="ruby-identifier">destroy!</span> <span class="ruby-comment cmt"># kills the alien</span>
        <span class="ruby-constant">Engine</span><span class="ruby-operator">::</span><span class="ruby-constant">Game</span>.<span class="ruby-identifier">game_state</span>.<span class="ruby-identifier">increase_score!</span>(<span class="ruby-value">50</span>) <span class="ruby-comment cmt"># award the player with some points</span>
      <span class="ruby-keyword kw">end</span>
    <span class="ruby-keyword kw">end</span>
    
    <span class="ruby-comment cmt"># destroy the bullet when it reaches the top of the screen or collides with an enemy</span>
    <span class="ruby-identifier">kill!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@y</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-operator">-</span><span class="ruby-ivar">@image</span>.<span class="ruby-identifier">height</span> <span class="ruby-operator">/</span> <span class="ruby-value">2</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">collide</span>
  <span class="ruby-keyword kw">end</span></pre>
</body>
</html>